//
//  ZCHeadView.m
//  zctx
//
//  Created by apple on 16/1/6.
//  Copyright © 2016年 sanliang. All rights reserved.
//

#import "ZCHeadView.h"

@implementation ZCHeadView
-(id)initWithFrame:(CGRect)frame andModel:(ZCInvolvedDetailsModelContent *)model{
    if (self = [super initWithFrame:frame]) {
        [self addImgViews];
        [self addNameLables];
        [self addTimeLables];
        [self addContentLables];
        
        self.nameLable.text = model.username;
        int timeInt =[model.btime intValue];
        self.timeLable.text = [NSString stringWithFormat:@"%@",stringDataWithTimeInterval(timeInt)];
        if (model.avatar.length>0) {
            [self.imgView sd_setImageWithURL:[NSURL URLWithString:model.avatar] placeholderImage:[UIImage imageNamed:@"projectdetail_icon"]];
        }else{
            self.imgView.image = [UIImage imageNamed:@"projectdetail_icon"];
        }
        NSLog(@"headView = %@",model.avatar);
    }
    return self;
}

-(void)addImgViews{
    [self addSubview:self.imgView];
    [self.imgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.centerY);
        make.height.mas_equalTo(45);
        make.left.equalTo(self.left).with.offset(18);
        make.width.mas_equalTo(45);
    }];
    self.imgView.layer.masksToBounds = YES;
    self.imgView.layer.cornerRadius = 45/2;
}

-(void)addNameLables{
    [self addSubview:self.nameLable];
    [self.nameLable mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.centerY).with.offset(-11);
        make.height.mas_equalTo(21);
        make.left.equalTo(self.imgView.right).with.offset(8);
        make.width.mas_equalTo(70);
    }];
}

-(void)addTimeLables{
    [self addSubview:self.timeLable];
    self.timeLable.textAlignment = NSTextAlignmentLeft;
    [self.timeLable mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.nameLable.centerY).with.offset(0);
        make.height.mas_equalTo(21);
        make.left.equalTo(self.nameLable.right).with.offset(5);
        make.right.equalTo(self.right).with.offset(-19);
    }];
}

-(void)addContentLables{
    [self addSubview:self.contentLable];
    [self.contentLable mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.centerY).with.offset(11);
        make.height.mas_equalTo(21);
        make.left.equalTo(self.imgView.right).with.offset(8);
        make.right.equalTo(self.right).with.offset(-19);
    }];
}

-(UIImageView *)imgView{
    if (!_imgView) {
        _imgView = [[UIImageView alloc]init];
        
    }
    return _imgView;
}

-(UILabel *)nameLable{
    if (!_nameLable) {
        _nameLable = [[UILabel alloc]init];
        _nameLable.text = @"sdfs";
        _nameLable.textAlignment = NSTextAlignmentLeft;
        _nameLable.font = [UIFont systemFontOfSize:13];
        _nameLable.textColor = [UIColor colorWithHexString:@"#8a8a8a"];
    }
    return _nameLable;
}

-(UILabel *)timeLable{
    if (!_timeLable) {
        _timeLable = [[UILabel alloc]init];
        _timeLable.text = @"2015-13-17";
        _timeLable.font = [UIFont systemFontOfSize:13];
        _timeLable.textColor = [UIColor colorWithHexString:@"#b2b2b2"];
    }
    return _timeLable;
}

-(UILabel *)contentLable{
    if (!_contentLable) {
        _contentLable = [[UILabel alloc]init];
        _contentLable.text = @"食品安全我做主，一起参与众测吧！";
        _contentLable.font = [UIFont systemFontOfSize:15];
        _contentLable.textColor = [UIColor colorWithHexString:@"#000000"];
    }
    return _contentLable;
}

@end
